package com.qianyu.project.service.handler;

import com.alibaba.fastjson.JSON;
import com.qianyu.project.core.annotation.FlowHandler;
import com.qianyu.project.core.bean.FormAudit;
import com.qianyu.project.core.context.handler.FlowFinishedHandler;
import com.qianyu.project.entity.IncomeContract;
import com.qianyu.project.entity.SubTenderPlan;
import com.qianyu.project.service.IIncomeContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@FlowHandler("income_contract")
public class IncomeContractPostProcessor implements FlowFinishedHandler {
    @Autowired
    IIncomeContractService incomeContractService;

    @Override
    public void postAllowHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit, "3");
    }

    @Override
    public void postRefuseHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit, "2");
    }

    /**
     * 通用的公共方法
     * @param jsonForm
     * @param formAudit
     * @param approveStatus
     */
    private void commonUpdate(String jsonForm, FormAudit formAudit, String approveStatus) {
        IncomeContract incomeContract = JSON.parseObject(jsonForm, IncomeContract.class);
        incomeContract.setApproveStatus(approveStatus);
        incomeContractService.updateById(incomeContract);
    }
}
